import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../layout/Layout.vue'
import CustomLayout from '../layout/CustomLayout.vue';

const routes = [
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    redirect: "/menu",
    children: [
      {
        path: 'menu',
        name: 'Menu',
        component: () => import("../views/Menu"),
      },
      {
        path: '/datalist',
        name: 'Datalist',
        component: () => import("../views/Datalist")
      },
      {
        path: '/browse',
        name: 'Browse',
        component: () => import("../views/Browse")
      },
      {
        path: '/statistics',
        name: 'Statistics',
        component: () => import("../views/Statistics")
      },
      {
        path: '/person',
        name: 'Person',
        component: () => import("../views/Person")
      },
    ]
  },
  {
    path: '/custom',
    name: 'CustomLayout',
    component: CustomLayout,
    children: [
      {
        path: '/customMenu',
        name: 'CustomMenu',
        component: () => import("../views/CustomMenu"),
      },
      {
        path: '/cart',
        name: 'Cart',
        component: () => import("../views/Cart")
      },
      {
        path: '/person2',
        name: 'Person2',
        component: () => import("../views/Person2")
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import("../views/Login")
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import("../views/Register")
  },
]


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 在刷新页面的时候重置当前路由
// activeRouter()
//
// function activeRouter() {
//   const userStr = sessionStorage.getItem("user")
//   if (userStr) {
//     const user = JSON.parse(userStr)
//     let root = {
//       path: '/',
//       name: 'Layout',
//       component: Layout,
//       redirect: "/menu",
//       children: []
//     }
//     user.permissions.forEach(p => {
//       let obj = {
//         path: p.path,
//         name: p.name,
//         component: () => import("../views/" + p.name)
//       };
//       root.children.push(obj)
//     })
//     if (router) {
//       router.addRoute(root)
//     }
//   }
// }

export default router
